package com.gorkr.labuladong.data_struct;

/**
 * @author gorkr
 * @date 2022/06/01 19:24
 **/
public class E235LowestCommonAncestorOfaBinarySearchTree {

    class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {

        return lowestCommonAncestor(root, p, q);
    }

    // 是否存在root是否是
    private TreeNode find(TreeNode root, TreeNode p, TreeNode q) {
        if (root == null) {
            return null;
        }
        if (p.val < root.val && q.val < root.val) {
            return find(root.left, p, q);
        } else if (p.val > root.val && q.val > root.val) {
            return find(root.right, p, q);
        }

        return root;
    }


}
    